package com.nage.components.display;

import android.util.Log;

import com.nage.components.Component;
import com.nage.components.movement.Physics;
import com.nage.components.movement.RandomMovement;
import com.nage.engine.GameGraph;
import com.nage.engine.GameGraphException;
import com.nage.engine.GameObject;

public class ShapeBuilder extends Component {

	// Creates numberToAdd shapes and adds them to the game graph.
	public ShapeBuilder(GameObject p, String strToAdd) {
		super(p);
		int numberToAdd = 0;
		if(strToAdd!=null) {
			numberToAdd = Integer.parseInt(strToAdd);
		}	
		GameGraph graph = parent.parent; // the game graph that this is all living in.
		for(int i = 0; i < numberToAdd; i++) {
			GameObject obj = new GameObject(graph); // new object we will add to the graph.
			Shape s = new Shape(obj);
			obj.setX(((float)1 / (float)numberToAdd) * i);
			s.x = obj.x;
			obj.setY(((float)1 / (float)numberToAdd) * i);
			s.x = obj.y;
			s.y = ((float)1 / (float)numberToAdd) * i;
			s.r = ((float)1 / (float)numberToAdd) * i;
			s.g = ((float)1 / (float)numberToAdd) * i;
			s.b = ((float)1 / (float)numberToAdd) * i;

			obj.addComponent(new Shape(obj));
			obj.addComponent(new RandomMovement(obj));
			obj.addComponent(new Physics(obj));
			try {
				obj.linkComponents();
			} catch (GameGraphException e) {
				Log.e("ShapeBuilder", "Bad component linking: "+e.getMessage());
			}
			graph.add(obj);
			Log.d("ShapeBuilder", "Shape "+i+" added ("+s.x+", "+s.y+")");
		}
		
	}

	@Override
	public void update(long delta) {
		// TODO Auto-generated method stub
		
	}

}
